<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>mindsensors-nxtcam-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     cam,                 sensorI2CCustomFastSkipStates)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: mindsensors-nxtcam-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * mindsensors-nxtcam.h provides an API for the Mindsensors NXTCam.  This program</span>
<span class="comment"> * demonstrates how to use that API.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> * - 0.2: More comments</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Gordon Wyeth for writing the original driver and cam_display program</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 28 November 2009</span>
<span class="comment"> * version 0.2</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="mindsensors-nxtcam_8h.html" title="Mindsensors NXTCam driver.">drivers/mindsensors-nxtcam.h</a>&quot;</span>

<span class="comment">// int xscale(int x) - Scales x values from camera coordinates to screen coordinates.</span>
<span class="keywordtype">int</span> xscale(<span class="keywordtype">int</span> x) {
  <span class="keywordflow">return</span> ((x - 12) * 99) / 175;
}

<span class="comment">// int yscale(int y) - Scales y values from camera coordinates to screen coordinates.</span>
<span class="keywordtype">int</span> yscale(<span class="keywordtype">int</span> y) {
  <span class="keywordflow">return</span> ((143 - y) * 63) / 143;
}

<span class="comment">/*</span>
<span class="comment"> Main task</span>
<span class="comment"> */</span>
task main () {
  <a name="a0"></a><a class="code" href="group__nxtcam.html#gaa3db0dd75c1de6e6a73579910a97f8e8">blob_array</a> _blobs;
  <span class="comment">// combine all colliding blobs into one</span>
  <span class="keywordtype">bool</span> _condensed = <span class="keyword">true</span>;

  <span class="comment">//blob_array _blobs;</span>
  <span class="keywordtype">int</span> _l, _t, _r, <a name="a1"></a><a class="code" href="group__d_temp.html#ga3ebf6b8694fd30e7ac8b82238e61ee7b">_b</a>;
  <span class="keywordtype">int</span> _nblobs;
  eraseDisplay();

  <span class="comment">// Initialise the camera</span>
  <a name="a2"></a><a class="code" href="group__nxtcam.html#gaa9503a35f45a1ffa5b298c65e95badf0">NXTCAMinit</a>(cam);
  <span class="keywordflow">while</span>(<span class="keyword">true</span>) {
    eraseDisplay();
    <span class="comment">// Fetch all the blobs, have the driver combine all</span>
    <span class="comment">// the colliding blobs.</span>
    _nblobs = <a name="a3"></a><a class="code" href="group__nxtcam.html#ga5259766d6514ee73a08421ac88e77b12">NXTCAMgetBlobs</a>(cam, _blobs, _condensed);
    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; _nblobs; i++) {
      <span class="comment">// Draw the scaled blobs</span>
      _l = xscale(_blobs[i].x1);
      _t = yscale(_blobs[i].y1);
      _r = xscale(_blobs[i].x2);
      _b = yscale(_blobs[i].y2);
      nxtFillRect(_l, _t, _r, _b);
    }

    nxtDisplayTextLine(1, <span class="stringliteral">&quot;%d&quot;</span>, _nblobs);
    wait1Msec(100);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: mindsensors-nxtcam-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
